import random

def generate_matrix(rows, cols, zero_probability=0.3):
    """生成一个随机的01矩阵"""
    return [[0 if random.random() < zero_probability else 1 for _ in range(cols)] for _ in range(rows)]

def generate_test_cases(num_cases=5):
    """生成测试用例"""
    test_cases = []
    
    # 添加一些特殊用例
    test_cases.extend([
        # 用例1：2x2矩阵
        [[0, 1],
         [1, 0]],
        
        # 用例2：3x3矩阵，中心为0
        [[1, 1, 1],
         [1, 0, 1],
         [1, 1, 1]],
        
        # 用例3：全1矩阵
        [[1, 1, 1],
         [1, 1, 1],
         [1, 1, 1]],
        
        # 用例4：全0矩阵
        [[0, 0, 0],
         [0, 0, 0],
         [0, 0, 0]],
    ])
    
    # 生成随机用例
    while len(test_cases) < num_cases:
        rows = random.randint(2, 10)
        cols = random.randint(2, 10)
        matrix = generate_matrix(rows, cols)
        if matrix not in test_cases:
            test_cases.append(matrix)
    
    return test_cases

def save_test_cases(test_cases, filename="test_cases.txt"):
    """保存测试用例到文件"""
    with open(filename, 'w') as f:
        for matrix in test_cases:
            f.write(f"Matrix:\n")
            for row in matrix:
                f.write(f"{row}\n")
            f.write("\n")
    print(f"已生成 {len(test_cases)} 个测试用例并保存到 {filename}")

def main():
    # 生成10个测试用例
    test_cases = generate_test_cases(10)
    save_test_cases(test_cases)

if __name__ == "__main__":
    main() 